### THIS REPLICATION SCRIPT PRODUCE THE REGRESSION MODELS AND TABLES IN THE SUPPLEMENTARY MATERIAL (APPENDIX)
### SECTION 1 PRODUCE REGRESSION MODELS AND TABLES AND SECTION 2 PRODUCE DESCRIPTIVE STATISTICS

# get packages ------------------------------------------------------------
pkgs <- c("tidyverse", "lubridate", "margins", "stargazer", "ggrepel",
          "xtable", "kableExtra", "texreg", "readxl") 
for (pkg in pkgs) library(pkg, character.only = TRUE)

# function for robust standard errors -------------------------------------
cl   <- function(dat,fm, cluster){
  require(sandwich, quietly = TRUE)
  require(lmtest, quietly = TRUE)
  M <- length(unique(cluster))
  N <- length(cluster)
  K <- fm$rank
  dfc <- (M/(M-1))*((N-1)/(N-K))
  uj  <- apply(estfun(fm),2, function(x) tapply(x, cluster, sum));
  vcovCL <- dfc*sandwich(fm, meat=crossprod(uj)/N)
  coeftest(fm, vcovCL) }

# load data ----------------------------------------------------------------
case <- read_excel("case_data.xlsx")
vote <- read_excel("indivdual_data.xlsx")

# make docket type factor variable
case$docket_type <- as.factor(case$docket_type)
levels(case$docket_type) <- list(
  Mandatory = "mandatory",
  Mandatory_principled = "mandatory principled",
  External_board = "external appeals board",
  Docket_control = "docket control"
)

# SECTION 1  --------------------------------------------------------------
# Effects of docket type on non-unanimity, dissent and reversal
# Models n1-n6: non-unanimous decisions
# NOTE: modelnames are constructed based on the first letter of the dependent variable (e.g non-unanimous = n)

# there are no dissents in the cases selected by the external appeals board committe cases. We drop this category from the analysis. 
case_reduced <- case %>% 
  filter(external_appeals_board==0)

# we drop external appeals board level from factor variable
#table(case_reduced$docket_type)
case_reduced$docket_type <- droplevels(case_reduced)$docket_type
#table(case_reduced$docket_type)

# intercept only model 
n1 <- glm(nonunanimous ~ 1,
          data = case_reduced,
          family = binomial('logit'))

# bivariate model including only docket type as predictor
n2 <- glm(nonunanimous ~ docket_type,
          data = case_reduced,
          family = binomial('logit'))

# controlling for panel size (this corresponds to model 1 in table 3 in the article)
n3 <- glm(nonunanimous ~ docket_type + seven_nine_justice_panels,
          data = case_reduced,
          family = binomial('logit'))

# controlling for international law
n4 <- glm(nonunanimous ~ docket_type + eu + echr,
          data = case_reduced,
          family = binomial('logit'))

# controlling for panel diversity
n5 <- glm(nonunanimous ~ docket_type + one_academic + minority_academics,
          data = case_reduced,
          family = binomial('logit')
)

# full model
n6 <- glm(nonunanimous ~ docket_type
          + seven_nine_justice_panels
          + eu
          + echr
          + one_academic
          + minority_academics, 
          data = case_reduced, 
          family = binomial('logit'))

# this code is is used to generate regression table A2
stargazer(n1, n2, n3, n4, n5, n6,
          digits = 2,
          header = F,
          style = "ajps",
          dep.var.labels= "Non-unanimity",
          title = "Table A2. Logistic regression models: non-unanimous decisions",
          covariate.labels = c("Docket type: mandatory principled",
                               "Docket type: discretionary",
                               "Enlarged panels",
                               "Eu",
                               "Echr",
                               "One academic",
                               "Minority academics"),
          type = "html",
          omit.stat = "ll",
          notes =  "Coefficients are logits. Standard errors in parentheses.", 
          out = "table A2.doc")


# Models d1-d6: dissent
# intercept only model
d1 <- glm(dissent_no_concurrence ~ 1, data = case_reduced, 
          family = binomial('logit'))

# bivariate model including only docket type as predictor
d2 <- glm(dissent_no_concurrence ~ docket_type, data = case_reduced, 
          family = binomial('logit'))

# controlling for panel size (this corresponds to model 2 in table 3 in the article)
d3 <- glm(dissent_no_concurrence ~ docket_type
          + seven_nine_justice_panels,
          data = case_reduced, 
          family = binomial('logit'))

# controlling for international law
d4<-glm(dissent_no_concurrence ~ docket_type
        + eu
        + echr, 
        data = case_reduced, 
        family = binomial('logit'))

# controlling for panel diversity
d5<-glm(dissent_no_concurrence ~ docket_type
        + one_academic
        + minority_academics, 
        data = case_reduced, 
        family = binomial('logit'))

# full model dissent
d6 <- glm(dissent_no_concurrence ~ docket_type
          + seven_nine_justice_panels
          + eu
          + echr
          + one_academic
          + minority_academics, 
          data = case_reduced, 
          family = binomial('logit'))

# this code is is used to generate regression table A3
stargazer(d1, d2, d3, d4, d5, d6,
          digits = 2,
          header = F,
          style = "ajps",
          dep.var.labels= "Dissent",
          title = "Table A3. Logistic regression models: dissent decisions",
          covariate.labels = c("Docket type: mandatory principled",
                               "Docket type: discretionary",
                               "Enlarged panels",
                               "Eu",
                               "Echr",
                               "One academic",
                               "Minority academics"),
          type = "html",
          omit.stat = "ll",
          notes =  "Coefficients are logits. Standard errors in parentheses.", 
          out = "table A3.doc")

# Models r1-r6: reversal
# intercept only model
r1 <- glm(reversal ~ 1, data = case, 
          family = binomial('logit'))

# bivariate docket type model
r2 <- glm(reversal ~ docket_type, data = case, 
          family = binomial('logit'))

# controlling for panel size
r3 <- glm(reversal ~ docket_type
          + seven_nine_justice_panels, data = case, 
          family = binomial('logit'))

# controlling for international law
r4<-glm(reversal ~ docket_type
        + eu
        + echr, data = case, 
        family = binomial('logit'))

# controlling for parties
r5 <- glm(reversal ~ docket_type
          + government_appellant
          + individuals, 
          data = case, 
          family = binomial('logit'))

# full model reversal (this corresponds to model 3 in table 3 in the manuscript)
r6 <- glm(reversal ~ docket_type
          + seven_nine_justice_panels
          + eu
          + echr
          + government_appellant
          + individuals, 
          data = case, 
          family = binomial('logit'))

# this code is used by author to generate regression table A4
stargazer(r1, r2, r3, r4, r5, r6,
          digits = 2,
          header = F,
          style = "ajps",
          dep.var.labels= "Reversal",
          title = "Table A4. Logistic regression models: reversal",
          covariate.labels = c("Docket type: mandatory principled",
                               "Docket type: external appeals board",
                               "Docket type: discretionary",
                               "Enlarged panels",
                               "Eu",
                               "Echr",
                               "Government appellant",
                               "Individuals"),
          type = "html",
          omit.stat = "ll",
          notes =  "Coefficients are logits. Standard errors in parentheses.", 
          out = "table A4.doc")

# Effects of docket type on the success of individual private litigants
# model g1- g6: government win
# use case_reduced data because of few observations on external appeal board

# intercept only model
g1 <- glm(government_win ~ 1,
          data = case_reduced, 
          family = binomial('logit'))

# docket type * individuals
g2 <- glm(government_win ~ docket_type
          + individuals
          + docket_type:individuals,
          data = case_reduced, 
          family = binomial('logit'))

# controlled for appellant party (this corresponds to model 4 in table 3 in the article)
g3 <- glm(government_win ~ docket_type
          + individuals
          + docket_type:individuals
          + government_appellant,
          data = case_reduced, 
          family = binomial('logit'))

# controlled for international law
g4 <- glm(government_win ~ docket_type
          + individuals
          + docket_type:individuals
          + eu
          + echr, 
          data = case_reduced, 
          family = binomial('logit'))

# controlled for panel diversity
g5 <- glm(government_win ~ docket_type
          + individuals
          + docket_type:individuals
          + government_majority
          + high_government_majority,
          data = case_reduced,
          family = binomial('logit'))

# governmnet win full model 
g6 <- glm(government_win ~ docket_type
          + individuals
          + docket_type:individuals
          + government_appellant
          + eu
          + echr
          + government_majority
          + high_government_majority,
          data = case_reduced,
          family = binomial('logit'))

# this code is used by author to generate regression table A5
stargazer(g1, g2, g3, g4, g5, g6,
          digits = 2,
          header = F,
          style = "ajps",
          dep.var.labels= "Government win",
          title = "Table A5. Logistic regression models: government win",
          covariate.labels = c("Docket type: mandatory principled",
                               "Docket type: discretionary",
                               "Individuals",
                               "Government appellant",
                               "Eu",
                               "Echr",
                               "Government majority",
                               "High Government majority",
                               "Docket type: mandatory principled * individuals",
                               "Docket type: discretionary * individuals"),
          type = "html",
          omit.stat = "ll",
          notes =  "Coefficients are logits. Standard errors in parentheses.", 
          out = "table A5.doc")

# Effects on docket type on attitudinal behavior
# subset data to nonunanimous decisions
nonunanimous <- as.data.frame(vote) %>% 
  filter(nonunanimous == 1) %>% 
  filter(!is.na(government_vote)) # we drop one case in the norwegian data with missing data on government vote because of unclear win

# subset data to discretionary docket 
nonunanimous_norway <- nonunanimous %>% 
  filter(docket_type == "Docket_control") %>% 
  mutate(independent_appointment = ifelse(appointment_year > 2002, 1, 0)) # independent appointment variable

# subset data to mandatory docket
nonunanimous_denmark <-  nonunanimous %>% 
  filter(docket_type != "Docket_control")

# docket control models (norway)
# NOTE: We name this models j(ustice).n[umber].c[ountry]. cl = cluster standard error models

# intercept only model for comparison
j1.norway <- glm(government_vote ~ 1, 
                 data = nonunanimous_norway,
                 family = binomial("logit"))

# clustered standard errors
cl.j1  <- cl(nonunanimous_norway, j1.norway , factor(nonunanimous_norway$judge_no))

# bivariate government career
j2.norway <- glm(government_vote ~ j.government, 
                 data = nonunanimous_norway,
                 family = binomial("logit"))

# clustered standard errors
cl.j2  <- cl(nonunanimous_norway, j2.norway , factor(nonunanimous_norway$judge_no))

# controlled for international law
j3.norway <- glm(government_vote ~ j.government
                 + eu 
                 + echr, 
                 data = nonunanimous_norway,
                 family = binomial("logit"))

# clustered standard errors
cl.j3  <- cl(nonunanimous_norway, j3.norway , factor(nonunanimous_norway$judge_no))


# controlled for parties 
j4.norway <- glm(government_vote ~ j.government
                 + individuals
                 + government_appellant, 
                 data = nonunanimous_norway,
                 family = binomial("logit"))

# clustered standard errors
cl.j4  <- cl(nonunanimous_norway, j4.norway , factor(nonunanimous_norway$judge_no))


# controlled for justices attributes 
j5.norway <- glm(government_vote ~ j.government
                 + seniority
                 + gender
                 + centre_born
                 + j.academic, 
                 data = nonunanimous_norway,
                 family = binomial("logit"))

# clustered standard errors
cl.j5  <- cl(nonunanimous_norway, j5.norway , factor(nonunanimous_norway$judge_no))

# controlled for appointment variables
j6.norway <- glm(government_vote ~ j.government
                 + appointing_government
                 + independent_appointment
                 + interim, 
                 data = nonunanimous_norway,
                 family = binomial("logit"))

# clustered standard errors
cl.j6 <- cl(nonunanimous_norway, j6.norway , factor(nonunanimous_norway$judge_no))

# full model
j7.norway <- glm(government_vote ~ j.government
                 + eu 
                 + echr
                 + individuals
                 + government_appellant
                 + seniority
                 + gender
                 + centre_born
                 + j.academic
                 + appointing_government
                 + independent_appointment
                 + interim,
                 data = nonunanimous_norway,
                 family = binomial("logit"))

# clustered standard errors
cl.j7 <- cl(nonunanimous_norway, j7.norway , factor(nonunanimous_norway$judge_no))

# generate table A6 (table in appendix is slightly edited in microsoft words)
htmlreg(list(j1.norway, j2.norway, j3.norway, j4.norway, j5.norway, j6.norway, j7.norway),
        custom.coef.names=c("Constant", "Government career", 
                            "Eu","Echr","Individuals", "Government appellant", "Seniority", "Gender",
                            "Centre born","Academic", "Appointing government", "Independent appointment","Interim"),
        override.se=list(cl.j1[,2],
                         cl.j2[,2],
                         cl.j3[,2],
                         cl.j4[,2],
                         cl.j5[,2],
                         cl.j6[,2],
                         cl.j7[,2]),
        override.pval=list(cl.j1[,4], 
                           cl.j2[,4], 
                           cl.j3[,4], 
                           cl.j4[,4], 
                           cl.j5[,4], 
                           cl.j6[,4],
                           cl.j7[,4]),
        stars = c(0.01, 0.05, 0.1), file = "table A6.doc", doctype = TRUE)

# Mandatory docket models 
# intercept only model for comparison
j1.denmark <- glm(government_vote ~ 1, 
                  data = nonunanimous_denmark,
                  family = binomial("logit"))

# clustered standard errors
cl.dj1  <- cl(nonunanimous_denmark, j1.denmark, factor(nonunanimous_denmark$judge_no))

# government career * docket type
j2.denmark <- glm(government_vote ~ j.government
                  + docket_type
                  + docket_type:j.government, 
                  data = nonunanimous_denmark,
                  family = binomial("logit"))

# clustered standard errors
cl.dj2  <- cl(nonunanimous_denmark, j2.denmark, factor(nonunanimous_denmark$judge_no))

# controlled for international law
j3.denmark <- glm(government_vote ~ j.government
                  + docket_type
                  + docket_type:j.government 
                  + eu,  
                  data = nonunanimous_denmark,
                  family = binomial("logit"))

# clustered standard errors
cl.dj3  <- cl(nonunanimous_denmark, j3.denmark, factor(nonunanimous_denmark$judge_no))

# controlled for parties 
j4.denmark <- glm(government_vote ~ j.government
                  + docket_type
                  + docket_type:j.government 
                  + individuals,
                  data = nonunanimous_denmark,
                  family = binomial("logit"))

# clustered standard errors
cl.dj4  <- cl(nonunanimous_denmark, j4.denmark, factor(nonunanimous_denmark$judge_no))

# controlled for justices attributes 
j5.denmark <- glm(government_vote ~ j.government
                  + docket_type
                  + docket_type:j.government
                  + seniority
                  + gender
                  + centre_born
                  + j.academic, 
                  data = nonunanimous_denmark,
                  family = binomial("logit"))

# clustered standard errors
cl.dj5 <- cl(nonunanimous_denmark, j5.denmark, factor(nonunanimous_denmark$judge_no))

# full model justice docket control
j6.denmark <- glm(government_vote ~ j.government
                  + docket_type
                  + docket_type:j.government
                  + eu 
                  + individuals
                  + seniority
                  + gender
                  + centre_born
                  + j.academic,
                  data = nonunanimous_denmark,
                  family = binomial("logit"))

# clustered standard errors
cl.dj6  <- cl(nonunanimous_denmark, j6.denmark, factor(nonunanimous_denmark$judge_no))

htmlreg(list(j1.denmark, j2.denmark, j3.denmark, j4.denmark, j5.denmark, j6.denmark),
        custom.coef.names=c('Constant', 'Government career', 'Docket type: mandatory principled',
                            'Docket type: mandatory principled * government career',
                            'Eu', 'Individuals', 'Seniority',
                            'Gender', 'Centre born', 'Academic'),
        override.se=list(cl.dj1[,2], 
                         cl.dj2[,2], 
                         cl.dj3[,2], 
                         cl.dj4[,2], 
                         cl.dj5[,2], 
                         cl.dj6[,2]),
        override.pval=list(cl.dj1[,4], 
                           cl.dj2[,4], 
                           cl.dj3[,4], 
                           cl.dj4[,4], 
                           cl.dj5[,4], 
                           cl.dj6[,4]),
        stars = c(0.01, 0.05, 0.1), file = "table A8.doc", doctype = TRUE)

# Docket control Norway 06 
nonunanimous_norway_06 <- nonunanimous_norway %>% 
  filter(case_year>2005)


j1.norway06 <- glm(government_vote ~ 1, 
                   data = nonunanimous_norway_06,
                   family = binomial("logit"))

# clustered standard errors
cl.j1.06  <- cl(nonunanimous_norway_06, j1.norway06 , factor(nonunanimous_norway_06$judge_no))


# bivariate government career
j2.norway06 <- glm(government_vote ~ j.government, 
                   data = nonunanimous_norway_06,
                   family = binomial("logit"))

# clustered standard errors
cl.j2.06  <- cl(nonunanimous_norway_06, j2.norway06 , factor(nonunanimous_norway_06$judge_no))


# controlled for international law 
j3.norway06 <- glm(government_vote ~ j.government
                   + eu 
                   + echr, 
                   data = nonunanimous_norway_06,
                   family = binomial("logit"))

# clustered standard errors
cl.j3.06  <- cl(nonunanimous_norway_06, j3.norway06 , factor(nonunanimous_norway_06$judge_no))

# controlled for parties
j4.norway06 <- glm(government_vote ~ j.government
                   + individuals
                   + government_appellant, 
                   data = nonunanimous_norway_06,
                   family = binomial("logit"))

# clustered standard errors
cl.j4.06  <- cl(nonunanimous_norway_06, j4.norway06 , factor(nonunanimous_norway_06$judge_no))

# controlled for justice attributes
j5.norway06 <- glm(government_vote ~ j.government
                   + seniority
                   + gender
                   + centre_born
                   + j.academic, 
                   data = nonunanimous_norway_06,
                   family = binomial("logit"))

# clustered standard errors
cl.j5.06  <- cl(nonunanimous_norway_06, j5.norway06 , factor(nonunanimous_norway_06$judge_no))

# controlled for appointment variables
j6.norway06 <- glm(government_vote ~ j.government
                   + appointing_government
                   + independent_appointment
                   + interim, 
                   data = nonunanimous_norway_06,
                   family = binomial("logit"))

# clustered standard errors
cl.j6.06  <- cl(nonunanimous_norway_06, j6.norway06 , factor(nonunanimous_norway_06$judge_no))

# docket control attitudinal norway 06 full model
j7.norway06 <- glm(government_vote ~ j.government
                   + eu 
                   + echr
                   + individuals
                   + government_appellant
                   + seniority
                   + gender
                   + centre_born
                   + appointing_government
                   + independent_appointment
                   + interim
                   + j.academic,
                   data = nonunanimous_norway_06,
                   family = binomial("logit"))

# clustered standard errors
cl.j7.06  <- cl(nonunanimous_norway_06, j7.norway06 , factor(nonunanimous_norway_06$judge_no))

# Generate table A8

htmlreg(list(j1.norway06, j2.norway06, j3.norway06, j4.norway06, j5.norway06, j6.norway06, j7.norway06),
        custom.coef.names=c("Constant", "Government career", 
                            "Eu","Echr","Individuals", "Government appellant", "Seniority", "Gender",
                            "Centre born","Academic", "Appointing government", "Independent appointment","Interim"),
        override.se=list(cl.j1.06[,2],
                         cl.j2.06[,2],
                         cl.j3.06[,2],
                         cl.j4.06[,2],
                         cl.j5.06[,2],
                         cl.j6.06[,2],
                         cl.j7.06[,2]),
        override.pval=list(cl.j1.06[,4], 
                           cl.j2.06[,4], 
                           cl.j3.06[,4], 
                           cl.j4.06[,4], 
                           cl.j5.06[,4], 
                           cl.j6.06[,4],
                           cl.j7.06[,4]),
        stars = c(0.01, 0.05, 0.1), file = "table A7.doc", doctype = TRUE)

# SECTION 2 -------------------------------------------------
# descriptive statistics control variables

court_of_appeals <-
  c(N = length(which(!is.na(case$court_of_appeals_discretion))),
    Mean = as.numeric(mean(case$court_of_appeals_discretion, na.rm = T)),
    Sd = as.numeric(sd(case$court_of_appeals_discretion, na.rm = T)),
    Min = as.numeric(min(case$court_of_appeals_discretion, na.rm = T)),
    Max = as.numeric(max(case$court_of_appeals_discretion, na.rm = T)))

eu <- c(
  N = length(which(!is.na(case$eu))),
  Mean = as.numeric(mean(case$eu, na.rm = T)),
  Sd = as.numeric(sd(case$eu, na.rm = T)),
  Min = as.numeric(min(case$eu, na.rm = T)),
  Max = as.numeric(max(case$eu, na.rm = T))
)

echr <- c(
  N = length(which(!is.na(case$echr))),
  Mean = as.numeric(mean(case$echr, na.rm = T)),
  Sd = as.numeric(sd(case$echr, na.rm = T)),
  Min = as.numeric(min(case$echr, na.rm = T)),
  Max = as.numeric(max(case$echr, na.rm = T))
)

government_appellant <-
  c(N = length(which(!is.na(case$government_appellant))),
    Mean = as.numeric(mean(case$government_appellant, na.rm = T)),
    Sd = as.numeric(sd(case$government_appellant, na.rm = T)),
    Min = as.numeric(min(case$government_appellant, na.rm = T)),
    Max = as.numeric(max(case$government_appellant, na.rm = T)))

enlarged_panel <-
  c(N = length(which(!is.na(case$seven_nine_justice_panels))),
    Mean = as.numeric(mean(case$seven_nine_justice_panels, na.rm = T)),
    Sd = as.numeric(sd(case$seven_nine_justice_panels, na.rm = T)),
    Min = as.numeric(min(case$seven_nine_justice_panels, na.rm = T)),
    Max = as.numeric(max(case$seven_nine_justice_panels, na.rm = T)))

government_majority <-
  c(
    N = length(which(!is.na(
      case$government_majority
    ))),
    Mean = as.numeric(mean(case$government_majority, na.rm = T)),
    Sd = as.numeric(sd(case$government_majority, na.rm = T)),
    Min = as.numeric(min(case$government_majority, na.rm = T)),
    Max = as.numeric(max(case$government_majority, na.rm = T))
  )

high_government_majority <-
  c(
    N = length(which(!is.na(
      case$high_government_majority
    ))),
    Mean = as.numeric(mean(case$high_government_majority, na.rm = T)),
    Sd = as.numeric(sd(case$high_government_majority, na.rm = T)),
    Min = as.numeric(min(case$high_government_majority, na.rm = T)),
    Max = as.numeric(max(case$high_government_majority, na.rm = T))
  )

one_academic <- c(
  N = length(which(!is.na(case$one_academic))),
  Mean = as.numeric(mean(case$one_academic, na.rm = T)),
  Sd = as.numeric(sd(case$one_academic, na.rm = T)),
  Min = as.numeric(min(case$one_academic, na.rm = T)),
  Max = as.numeric(max(case$one_academic, na.rm = T))
)

minority_academics <-
  c(
    N = length(which(!is.na(
      case$minority_academics
    ))),
    Mean = as.numeric(mean(case$minority_academics, na.rm = T)),
    Sd = as.numeric(sd(case$minority_academics, na.rm = T)),
    Min = as.numeric(min(case$minority_academics, na.rm = T)),
    Max = as.numeric(max(case$minority_academics, na.rm = T))
  )


attorney <- c(N=length(which(!is.na(nonunanimous$j.attorney))),
              Mean = as.numeric(mean(nonunanimous$j.attorney, na.rm = T)), 
              Sd = as.numeric(sd(nonunanimous$j.attorney, na.rm = T)), 
              Min = as.numeric(min(nonunanimous$j.attorney, na.rm = T)), 
              Max = as.numeric(max(nonunanimous$j.attorney, na.rm = T)))

academic <- c(N=length(which(!is.na(nonunanimous$j.academic))),
              Mean = as.numeric(mean(nonunanimous$j.academic, na.rm = T)), 
              Sd = as.numeric(sd(nonunanimous$j.academic, na.rm = T)), 
              Min = as.numeric(min(nonunanimous$j.academic, na.rm = T)), 
              Max = as.numeric(max(nonunanimous$j.academic, na.rm = T)))

judge <- c(N=length(which(!is.na(nonunanimous$j.judge))),
           Mean = as.numeric(mean(nonunanimous$j.judge, na.rm = T)), 
           Sd = as.numeric(sd(nonunanimous$j.judge, na.rm = T)), 
           Min = as.numeric(min(nonunanimous$j.judge, na.rm = T)), 
           Max = as.numeric(max(nonunanimous$j.judge, na.rm = T)))

gender <- c(N=length(which(!is.na(nonunanimous$gender))),
            Mean = as.numeric(mean(nonunanimous$gender, na.rm = T)), 
            Sd = as.numeric(sd(nonunanimous$gender, na.rm = T)), 
            Min = as.numeric(min(nonunanimous$gender, na.rm = T)), 
            Max = as.numeric(max(nonunanimous$gender, na.rm = T)))

centre_born <- c(N=length(which(!is.na(nonunanimous$centre_born))),
                 Mean = as.numeric(mean(nonunanimous$centre_born, na.rm = T)), 
                 Sd = as.numeric(sd(nonunanimous$centre_born, na.rm = T)), 
                 Min = as.numeric(min(nonunanimous$centre_born, na.rm = T)), 
                 Max = as.numeric(max(nonunanimous$centre_born, na.rm = T)))

seniority <- c(N=length(which(!is.na(nonunanimous$seniority))),
               Mean = as.numeric(mean(nonunanimous$seniority, na.rm = T)), 
               Sd = as.numeric(sd(nonunanimous$seniority, na.rm = T)), 
               Min = as.numeric(min(nonunanimous$seniority, na.rm = T)), 
               Max = as.numeric(max(nonunanimous$seniority, na.rm = T)))

appointing_government <- c(N=length(which(!is.na(nonunanimous_norway$appointing_government))),
                           Mean = as.numeric(mean(nonunanimous_norway$appointing_government)), 
                           Sd = as.numeric(sd(nonunanimous_norway$appointing_government)), 
                           Min = as.numeric(min(nonunanimous_norway$appointing_government)), 
                           Max = as.numeric(max(nonunanimous_norway$appointing_government)))

independent_appointment <- c(N=length(which(!is.na(nonunanimous_norway$independent_appointment))),
                             Mean = as.numeric(mean(nonunanimous_norway$independent_appointment)), 
                             Sd = as.numeric(sd(nonunanimous_norway$independent_appointment)), 
                             Min = as.numeric(min(nonunanimous_norway$independent_appointment)), 
                             Max = as.numeric(max(nonunanimous_norway$independent_appointment)))

interim <- c(N=length(which(!is.na(nonunanimous_norway$interim))),
             Mean = as.numeric(mean(nonunanimous_norway$interim)), 
             Sd = as.numeric(sd(nonunanimous_norway$interim)), 
             Min = as.numeric(min(nonunanimous_norway$interim)), 
             Max = as.numeric(max(nonunanimous_norway$interim)))


control_vars <- rbind(court_of_appeals, eu, echr, government_appellant, enlarged_panel,
                      government_majority, high_government_majority,
                      one_academic, minority_academics, attorney, academic, judge, gender, centre_born, seniority,
                      appointing_government, independent_appointment, interim)

control_vars<-as.data.frame(control_vars) %>% 
  mutate(Variable = c("Court of appeals discretion", 
                      "Eu", 
                      "Echr",
                      "Government appellant",
                      "Enlarged panel",
                      "Government_majority",
                      "High government majority",
                      "One academic",
                      "Minority academics",
                      "Career: attorney",
                      "Career: academic",
                      "Career: judge",
                      "Gender",
                      "Centre born",
                      "Seniority",
                      "Appointing government",
                      "Independent appointment",
                      "Interim")) %>% 
  select(Variable, N, Mean, Sd, Min, Max)

stargazer(control_vars, 
          digits = 2, 
          header = F,
          rownames = F,
          summary = F,
          title = "Table A1: Descriptive statistics control variables",
          type = "html",
          out = "table A1.doc")
